//package com.huahua.api.scheduled;
//
//import com.huahua.api.api.HolidayApi;
//import com.huahua.api.entity.pojo.ApiHoliday;
//import com.huahua.api.service.ApiHolidayService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.io.IOException;
//import java.util.List;
//import java.util.Set;
//import java.util.stream.Collectors;
//
//
///**
// * @author LoveHuahua
// * 定时更新数据
// */
//@Configuration
//public class HolidayScheduleTask {
//
//    @Autowired
//    HolidayApi holidayApi;
//
//
//    @Autowired
//    ApiHolidayService apiHolidayService;
//
//
//    /**
//     * 每天凌晨1点执行一次
//     * 定时同步节假日数据
//     */
//    @Scheduled(cron = "0 0 1 * * ?")
////    @Scheduled(fixedDelay = 1000 * 60 * 60)
////    @Transactional(rollbackFor = Exception.class)
//    public void configureTasks() throws IOException {
//        //所有的id集合
//        List<ApiHoliday> list = apiHolidayService.lambdaQuery().select(ApiHoliday::getId).list();
//        Set<Integer> collect = list.stream().map(ApiHoliday::getId).collect(Collectors.toSet());
//
//        List<ApiHoliday> countries = holidayApi.getCountries();
//        for (ApiHoliday country : countries) {
//            ApiHoliday one = apiHolidayService.lambdaQuery().eq(ApiHoliday::getName, country.getName()).eq(ApiHoliday::getCountry, country.getCountry()).eq(ApiHoliday::getHolidayTime, country.getHolidayTime()).one();
//            if (one == null) {
//                apiHolidayService.save(country);
//            } else {
//                //存在,可能需要更新
//                country.setId(one.getId());
//                apiHolidayService.updateById(country);
//                collect.remove(one.getId());
//            }
//        }
//
//        //清空id
//        apiHolidayService.removeByIds(collect);
//    }
//}